package me.yricky.cov_spectrum.ui.content

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import me.yricky.cov_spectrum.model.beans.PangoLineageItem

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun PangoLineageList(
    modifier: Modifier = Modifier,
    list: List<PangoLineageItem>,
    alias:((String)->String)? = null,
    onClick:(PangoLineageItem)->Unit = {},
){
    LazyVerticalGrid(columns = GridCells.Adaptive(280.dp),modifier = modifier){
        items(list, key = { it.pangoLineage() }){ item ->
            Surface(
                modifier = Modifier.padding(4.dp).animateItemPlacement(),
                shape = RoundedCornerShape(8.dp),
                color = MaterialTheme.colors.surface,
                elevation = 4.dp
            ) {
                Box{
                    Column(
                        Modifier
                            .fillMaxSize()
                            .clickable { onClick(item) }
                            .padding(4.dp)) {
                        Text(text = item.pangoLineage(), style = MaterialTheme.typography.h5)
                        alias?.let{
                            Text(text = it(item.pangoLineage()))
                        }
                        Text(text = "count:${item.count}")
                    }
                    VOCBadge(
                        modifier = Modifier.align(Alignment.TopEnd),
                        fullName = alias?.invoke(item.pangoLineage()) ?: item.pangoLineage())

                }
            }

        }
    }
}